package com.etop.service;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.etop.dao.RoleDao;
import com.etop.pojo.Role;


/**
 * 类名:RoleService  角色服务和DAO对接
 * @author Administrator
 *
 */
@SuppressWarnings("serial")
@Service
public class RoleService implements Serializable {
	
	@Resource
    private RoleDao roleDao;
	
	
	public List<Role> getAllRole(){
		return roleDao.find("from Role");
	}
	public Role findById(int id){
		Map<String,Object> params=new HashMap<String,Object>();
		params.put("id", id);
		return (Role) roleDao.findUniqueResult("form Role where id=:id", params);
	}
	public void updateRole(Role role){
		roleDao.saveOrUpdate(role);
	}
	public void saveRole(Role role){
		roleDao.save(role);
	}
	public void deleteRole(int id){
		roleDao.deleteById(id);
	}
	public String getNameById(int role_id){
		Map<String,Object> params=new HashMap<String,Object>();
		params.put("id", role_id);
		Role role=(Role) roleDao.findUniqueResult("from Role where id=:id", params);
		return role.getRolename();
	}
}
